<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ES6标准</title>
</head>
<body>
    <h2>运算符的扩展</h2>
    <script>
        //es6之扩展运算符 三个点(...)
        //1. 对象的扩展运算符
        let stu1 = {name:'李四', age:22, sex:'男'};
        //同一对象
        // let stu2 = stu1;
        //克隆一份（独立）
        let stu2 = {...stu1};
        stu2.age = 30;
        console.log(stu1);
        console.log(stu2);
        console.log("=".repeat(30));
        //2. 数组的扩展运算符
        let a1 = [10, 20, 30, 40];
        // let a2 = a1;
        let a2 = [...a1];
        a2[1] = 21;
        console.log(a1);
        console.log(a2);
        console.log("=".repeat(30));
        //3. 剩余参数的处理 
        function demo(x, y, z) {
            console.log(x, y, z);
        }
        let a = [10, 20 ,30];
        // demo(a[0], a[1], a[2]);
        demo(...a);
        console.log("=".repeat(30));
        //接受剩余参数
        // function demo2(name...params) {

        // }
        function demo2(...params) {
            console.log(params);
        }
        demo2("aa", "bb");
        demo2("aa", "bb", "cc", "dd");
        demo2("aa", "bb", "cc");
        console.log("=".repeat(30));

        //解构赋值
        let arr = [10,20,30,40,50,60,70];
        let [id1, id2, ...idn] = arr;
        console.log(id1);
        console.log(id2);
        console.log(idn);
    </script>
</body>
</html>